<?php 

require_once(dirname(__FILE__).'/commons/CFPropertyList.php');
require_once(dirname(__FILE__).'/database/functions.php');

header("Content-type: application/xml");



function makePlist($allEventos) 
{
	$plist = new CFPropertyList();
	$plist->add( $dict = new CFDictionary());

	$plistEventos = new CFArray();
	

	foreach ($allEventos as $evento) {

		$plistEvento = new CFDictionary();
		$plistEvento->add('Nombre', new CFString($evento['nombre']));
		$plistEvento->add('Descripcion', new CFString($evento['descripcion']));
		$plistEvento->add('StartDate', new CFDate($evento['startDate']));
		$plistEventos->add($plistEvento);
	}
	$dict->add('eventos', $plistEventos);
	return $plist->toXML();
}


$path = $_SERVER[PATH_INFO];
if ($path != null) {
	$path_params = preg_split('/\//', $path);
}

switch($_SERVER['REQUEST_METHOD']) {
	case('GET'):
		if ($path_params[1] != null && $path_params[2] != null) {
			if ( strtolower($path_params[1]) == 'curso') {
				$allEventos = getEventosCurso($path_params[2]);
			}
			
		}
		else {
			$allEventos = getEventos();
		}
		echo makePlist($allEventos);
			
		break;
}
